<template>
  <div id="userLoginView">
    <div>
      <h2 style="text-align: center; margin-bottom: 16px">用户注册</h2>
      <a-form
        style="max-width: 480px; margin: 0 auto"
        :model="form"
        @submit="handleSubmit"
        label-align="left"
        auto-label-width
      >
        <a-form-item field="userAccount" tooltip="" label="用户名:">
          <a-input v-model="form.userAccount" placeholder="请输入用户名" />
        </a-form-item>
        <a-form-item field="userPassword" label="密码:">
          <a-input-password
            v-model="form.userPassword"
            placeholder="请输入密码"
          />
        </a-form-item>
        <a-form-item field="post" label="确认密码:">
          <a-input-password
            v-model="form.checkPassword"
            placeholder="请确认密码"
          />
        </a-form-item>
        <a-form-item field="isRead">
          <!--        <a-checkbox v-model="form.isRead">我啥都同意</a-checkbox>-->
        </a-form-item>
        <a-form-item>
          <a-button type="primary" html-type="submit">登录</a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";
import { UserControllerService, UserRegisterRequest } from "../../../generated";
import { useStore } from "@/store/index";
import { Message } from "@arco-design/web-vue";
import { useRouter } from "vue-router";

const router = useRouter();
const store = useStore();

const form = reactive({
  userAccount: "",
  userPassword: "",
  checkPassword: "",
} as UserRegisterRequest);

const handleSubmit = async () => {
  const res = await UserControllerService.userRegisterUsingPost(form);
  if (res.code === 0) {
    router.push({
      path: "/user/login",
      replace: true,
    });
    Message.success({
      content: "注册成功！",
    });
  } else {
    Message.error({
      content: res.message,
    });
  }
};
</script>

<style scoped>
#userLoginView {
}
</style>
